package com.bjsxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjsxt.domain.EntrustOrder;
import com.bjsxt.domain.Market;
import com.bjsxt.mapper.EntrustOrderMapper;
import com.bjsxt.service.EntrustOrderService;
import com.bjsxt.service.MarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class EntrustOrderServiceImpl extends ServiceImpl<EntrustOrderMapper, EntrustOrder> implements EntrustOrderService {
    /**
     * 交易市场业务层
     */
    @Autowired
    private MarketService marketService;

    /**
     * 分页查询委托记录数据
     *
     * @param page   分页对象<EntrustOrder>
     * @param userId 用户 ID
     * @param symbol 交易对标识
     * @param type   买卖类型：1-买入；2-卖出,2 卖出
     * @return 委托记录集合
     */
    @Override
    public Page<EntrustOrder> pageByUserIdAndSymbolAndType(Page<EntrustOrder> page, Long userId, String symbol, Byte type) {
        // 调用分页方法进行数据的查询
        return page(page, new LambdaQueryWrapper<EntrustOrder>()
                .eq(EntrustOrder::getUserId, userId)
                .eq(!StringUtils.isEmpty(symbol), EntrustOrder::getSymbol, symbol)
                .eq(type != null && type != 0, EntrustOrder::getType, type)
                .orderByDesc(EntrustOrder::getCreated));
    }
}
